﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Patyk.MapEdit
{
    public class NewMapVM
    {
        public string Name { get; set; }
        public int Width { get; set; }
        public int Height { get; set; }
    }

    /// <summary>
    /// Interaction logic for NewMapModal.xaml
    /// </summary>
    public partial class NewMapModal : Window
    {
        public NewMapModal()
        {
            InitializeComponent();
        }

        public NewMapVM ShowNewMapDialog()
        {
            var dialog = this.ShowDialog();
            if (!dialog.HasValue || !dialog.Value || string.IsNullOrEmpty(nameTxBox.Text) ||
                string.IsNullOrEmpty(widthTxBox.Text) || string.IsNullOrEmpty(heightTxBox.Text))
                return null;

            this.Close();
            return new NewMapVM
                {
                    Name = nameTxBox.Text,
                    Height = Convert.ToInt32(heightTxBox.Text),
                    Width = Convert.ToInt32(widthTxBox.Text)
                };
        }

        private void heightTxBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            e.Handled = !Char.IsNumber(Convert.ToChar(e.Text));

            base.OnPreviewTextInput(e);
        }

        private void widthTxBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            e.Handled = !Char.IsNumber(Convert.ToChar(e.Text));

            base.OnPreviewTextInput(e);
        }

        private void okBtn_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void noBtn_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;

        }
    }
}
